#pragma once
#include <so_math.h>
class Vector2
{
public:
    real x = 0, y = 0;

public:
    Vector2() = default;
    ~Vector2() = default;
    inline Vector2(real x, real y) : x(x), y(y)
    {
    }
    inline bool operator==(const Vector2 &v) const
    {
        return x == v.x && y == v.y;
    }
    inline bool operator!=(const Vector2 &v) const
    {
        return !(*this == v);
    }
    inline Vector2 operator-() const
    {
        return Vector2(-x, -y);
    }

    inline Vector2 operator-(const Vector2 &v) const
    {
        return Vector2(x - v.x, y - v.y);
    }
    inline Vector2 operator+(const Vector2 &v) const
    {
        return Vector2(x + v.x, y + v.y);
    }
    inline Vector2 &operator+=(const Vector2 &v)
    {
        x += v.x;
        y += v.y;
        return *this;
    }
    inline Vector2 &operator-=(const Vector2 &v)
    {
        x -= v.x;
        y -= v.y;
        return *this;
    }
    inline Vector2 operator*(real r)
    {
        return Vector2(x * r, y * r);
    }
    inline Vector2 operator/(real r)
    {
        if (r == 0)
        {
            return Vector2();
        }
        return Vector2(x / r, y / r);
    }
    inline Vector2 &operator/=(real r)
    {
        if (r == 0)
        {
            return *this;
        }
        x = x / r;
        y = y / r;
        return *this;
    }
    inline real length()
    {
        return so_sqrt(x * x + y * y);
    }
    inline real length2()
    {
        return x * x + y * y;
    }
    inline real operator*(const Vector2 &v) const
    {
        return x * v.y - y * v.x;
    }
    inline real dot(const Vector2 &v) const
    {
        return x * v.x + y * v.y;
    }
    inline Vector2 normalized()
    {
        real len = length();
        if (len == 0)
        {
            return Vector2();
        }
        return Vector2(x / len, y / len);
    }
    inline Vector2 getRotationOffset(Vector2 center, real rad)
    {
        real len = (*this - center).length();
        return Vector2(x + len * so_cos(rad), y + len * so_sin(rad));
    }
};